<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form size="small" :model="queryParams" class="formBox" label-width="88px">
        <el-row :gutter="0">
          <el-col :span="5">
            <el-form-item label="校区" prop="gradeId" class="width_100">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择校区"
                filterable
                style="width: 100%"
              >
                <el-option value="1" label="开启"></el-option>
                <el-option value="2" label="关闭"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="年级" prop="gradeId" class="width_100">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择年级名称"
                style="width: 100%"
                filterable
                @change="gradeFun"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="班级" prop="classId" class="width_100">
              <el-select
                v-model="queryParams.classId"
                placeholder="请选择班级"
                filterable
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in classList"
                  :key="index"
                  :value="item.id"
                  :label="item.className"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="姓名" prop="studentName" class="width_100">
              <el-input
                placeholder="请输入姓名"
                v-model="queryParams.studentName"
                style="width: 100%"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="身份证号" prop="idNumber" class="width_100">
              <el-input
                placeholder="请输入身份证号"
                v-model="queryParams.idNumber"
                style="width: 100%"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="性别" prop="sex" class="width_100">
              <el-select
                v-model="queryParams.sex"
                placeholder="请选择性别"
                style="width: 100%"
              >
                <el-option value="1" label="男"></el-option>
                <el-option value="0" label="女"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="团餐状态" prop="status" class="width_100">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择团餐状态"
                style="width: 100%"
              >
                <el-option value="1" label="启用"></el-option>
                <el-option value="2" label="停用"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="所属折扣" prop="gradeId" class="width_100">
              <el-select
                v-model="queryParams.status"
                placeholder="请选择所属折扣"
                style="width: 100%"
              >
                <el-option value="1" label="开启"></el-option>
                <el-option value="2" label="关闭"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item>
              <div class="dis aic">
                <div class="flex_1"></div>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="handleQuery"
                >
                  搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
                  重置
                </el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- 按钮 -->
    <el-card class="search-card">
      <el-row :gutter="10" class="mb8">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="buttonMethods(1)"
          v-hasPermi="['campus:unpaid:export']"
        >
          添加
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-s-tools"
          size="mini"
          @click="buttonMethods(4)"
          v-hasPermi="['campus:unpaid:export']"
        >
          批量团餐
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-s-tools"
          size="mini"
          @click="buttonMethods(5)"
          v-hasPermi="['campus:unpaid:export']"
        >
          批量所局折扣
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-s-tools"
          size="mini"
          @click="buttonMethods(6)"
          v-hasPermi="['campus:unpaid:export']"
        >
          批量餐标类型
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="buttonMethods(7)"
          v-hasPermi="['campus:unpaid:export']"
        >
          导入
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['campus:unpaid:export']"
        >
          导出
        </el-button>

        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card">
      <el-table :data="dataList">
        <el-table-column label="学生姓名" align="center" prop="idCardNumber" />
        <el-table-column label="身份证号" align="center" prop="idCardNumber" />
        <el-table-column label="校区" align="center" prop="idCardNumber" />
        <el-table-column label="年级" align="center" prop="idCardNumber" />
        <el-table-column label="班级" align="center" prop="idCardNumber" />
        <el-table-column label="性别" align="center" prop="idCardNumber" />
        <el-table-column label="联系电话" align="center" prop="idCardNumber" />
        <el-table-column label="团餐状态" align="center" prop="idCardNumber" />
        <el-table-column label="所属折扣" align="center" prop="idCardNumber" />
        <el-table-column label="餐标类型" align="center" prop="idCardNumber" />
        <el-table-column label="创建时间" align="center" prop="idCardNumber" />
        <el-table-column label="创建人" align="center" prop="idCardNumber" />
        <el-table-column label="操作" align="center" width="200px">
          <template slot-scope="scope">
            <el-button
              type="warning"
              size="mini"
              class="padding_4_10"
              @click="buttonMethods(1, scope.row)"
              v-hasPermi="['campus:grade:edit']"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="dis aic fs_14 margin_top_20">
        <div class="margin_left_20">学生总人数：2298人</div>
        <div class="margin_left_20">正常订餐：2000人</div>
        <div class="margin_left_20">暂停订餐：298人</div>
        <div class="margin_left_20">普通餐：2000人</div>
        <div class="margin_left_20">清真餐：298人</div>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!--  -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="queryForm" label-width="95px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="校区名称" prop="gradeId" style="width: 100%">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择校区名称"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级" prop="gradeId" style="width: 100%">
              <el-select
                v-model="queryForm.gradeId"
                placeholder="请选择班级"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生姓名" prop="gradeName" class="is-required">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入学生姓名"
                maxlength="30"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="gradeName" class="is-required">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入身份证号"
                maxlength="18 "
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gradeName" class="is-required">
              <el-radio-group v-model="queryForm.radio">
                <el-radio label="1">男</el-radio>
                <el-radio label="0">女</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="餐标类型" prop="gradeName" class="is-required">
              <el-radio-group v-model="queryForm.radio">
                <el-radio label="1">普通餐</el-radio>
                <el-radio label="2">清真餐</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="团餐状态" prop="gradeName" class="is-required">
              <el-radio-group v-model="queryForm.radio">
                <el-radio label="1">正常订餐</el-radio>
                <el-radio label="2">暂停订单</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属折扣" prop="gradeId" style="width: 100%">
              <el-select
                v-model="queryParams.gradeId"
                placeholder="请选择所属折扣"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :value="item.id"
                  :label="item.gradeName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="gradeName" class="is-required">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入联系人"
                maxlength="30"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="gradeName" class="is-required">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入联系电话"
                maxlength="11"
                show-word-limit
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="gradeName">
              <el-input
                v-model="queryForm.gradeName"
                placeholder="请输入备注"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buttonMethods(2)">确 定</el-button>
        <el-button @click="buttonMethods(3)">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 批量团餐 -->
    <el-dialog :title="title" :visible.sync="PLTC_STATUS" width="40%" append-to-body>
      <el-form ref="form" :model="queryForm" label-width="95px">
        <el-form-item label="团餐状态" prop="gradeId" style="width: 100%">
          <el-radio-group v-model="queryForm.radio">
            <el-radio label="1">正常订餐</el-radio>
            <el-radio label="2">暂停订单</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buttonMethods">确 定</el-button>
        <el-button @click="buttonMethods">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 批量所属折扣 -->
    <el-dialog :title="title" :visible.sync="PLSSZK_STATUS" width="40%" append-to-body>
      <el-form ref="form" :model="queryForm" label-width="95px">
        <el-form-item label="餐标类型" prop="gradeId" style="width: 100%">
          <el-radio-group v-model="queryForm.radio">
            <el-radio label="1">普通餐</el-radio>
            <el-radio label="2">清真餐</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buttonMethods">确 定</el-button>
        <el-button @click="buttonMethods">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 批量餐标类型 -->
    <el-dialog :title="title" :visible.sync="PLCBLX_STATUS" width="40%" append-to-body>
      <el-form ref="form" :model="queryForm" label-width="95px">
        <el-form-item label="餐标类型" prop="gradeId" style="width: 100%">
          <el-select
            v-model="queryParams.gradeId"
            placeholder="请选择餐标类型"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in gradeList"
              :key="index"
              :value="item.id"
              :label="item.gradeName"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buttonMethods">确 定</el-button>
        <el-button @click="buttonMethods">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 人员导入 -->
    <el-dialog title="人员导入" :visible.sync="importStatus" width="500px" append-to-body>
      <div style="width: 100%">
        <el-button type="primary" @click="xzmb">下载模板</el-button>
        <div style="text-align: center; margin-top: 20px">
          <file-upload @success="fileSuccess" />
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="importStatus = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listGrade } from "@/api/campus/grade";
import { listClassManage } from "@/api/campus/classManage";

export default {
  name: "studentteamMeal",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 1,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      dataList: [],
      campusList: [],
      gradeList: [],
      classList: [],
      queryForm: {},
      PLTC_STATUS: false,
      PLSSZK_STATUS: false,
      PLCBLX_STATUS: false,
      importStatus: false,
    };
  },
  created() {
    this.getList();
    this.listGradeFun();
    this.gradeFun();
  },
  activated() {},
  methods: {
    // 列表
    getList() {},

    /**
     * 获取成绩列表
     */
    listGradeFun() {
      listGrade({ pageNum: 1, pageSize: 200 }).then((res) => {
        if (res.code == 200) {
          this.gradeList = res.rows;
        }
      });
    },
    /**
     * 获取指定年级的班级列表
     *
     * @param options 包含年级ID的对象
     */
    gradeFun(options) {
      this.$set(this.queryParams, "classId", "");
      listClassManage({ pageNum: 1, pageSize: 200, gradeId: options }).then(
        (response) => {
          this.classList = response.rows;
        }
      );
    },
    /**
     * 按钮操作的方法
     *
     * @param options 操作选项，用于区分不同的按钮操作
     * @param value 按钮值
     */
    buttonMethods(options, value) {
      // 添加 修改
      if (options == 1) {
        if (value) {
          this.title = "修改";
          this.queryForm = { ...value };
          this.open = true;
        } else {
          this.title = "添加";
          this.queryForm = {};
          this.open = true;
        }
      }
      // 提交
      else if (options == 2) {
        var data = { ...this.queryForm };
        console.log(data);
      }
      // 关闭弹框
      else if (options == 3) {
        this.title = "";
        this.queryForm = {};
        this.open = false;
      } else if (options == 4) {
        this.title = "批量团餐";
        this.PLTC_STATUS = true;
      } else if (options == 5) {
        this.title = "批量所属折扣";
        this.PLSSZK_STATUS = true;
      } else if (options == 6) {
        this.title = "批量餐标类型";
        this.PLCBLX_STATUS = true;
      } else if (options == 7) {
        this.importStatus = true;
        this.title = "团餐人员导入";
      }
    },
    fileSuccess() {
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.listGradeFun();
      this.gradeFun();
    },
    // 导出
    handleExport() {
      this.download("", { ...this.queryParams }, `学生团餐管理.xlsx`);
    },
    xzmb() {},
  },
};
</script>
<style>
.padding_4_10 {
  padding: 4px 10px !important;
}

.el-upload--picture-card {
  width: 90px !important;
  height: 90px !important;
  line-height: 90px !important;
}

.formBox >>> .el-form-item--small.el-form-item {
  margin-bottom: 0px !important;
}

.formBox >>> .el-form-item__label {
  font-size: 12px !important;
  padding: 0 !important;
}
</style>
